/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package kuti.grp5;

import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.*;
import kuti.EWorldElementType;
import kuti.IKuti;
import kuti.IObservableLawn;

/**
 * @author Marc Schorderet <marc.schorderet@edu.hefr.ch>
 * @version 1.0
 *
 * @see IObservableLawn
 */

public class ObservableLawn implements IObservableLawn {
    
    /**
     * The lawn area
     */
    
    private int[][] lawn;
    
    /**
     * The current kuti
     */
    
    private IKuti kuti;
    
    /**
     * The radar line
     */
    
    private Line2D radar;
    
    /**
     * The lawn height list
     */
    
    private List<Integer> lawnProfile;
    
    /**
     * The constructor create a list of lawn height.
     * 
     * @param kuti  The kuti
     * @param radar The radar line of the kuti
     * @param lawn  The lawn information
     * 
     */
    
    public ObservableLawn(IKuti kuti, Line2D radar, Lawn lawn){
        
        this.kuti = kuti;
        this.radar = radar;
        this.lawn = lawn.getLawn();
        
        // Create the lawn height list
        this.lawnProfile = new LinkedList<Integer>();
        
        // Fill the list
        createLawnProfile();
        
    }
    
    /**
     * This method returns the lawn height list
     * 
     * @return Returns the lawn height list
     * 
     */
    
    @Override
    public List<Integer> getLawnHeightProfile() {
        return lawnProfile;
    }
    
    /**
     * This method returns the element type
     * 
     * @return Returns the element type
     */

    @Override
    public EWorldElementType getElementType() {
        return EWorldElementType.LAWN;
    }
    
    
    /**
     * This method fill the lawn height list.
     * 
     */
    
    private void createLawnProfile(){
        
        Set<Point2D> points = RadarHelper.getPointProfile(kuti.getCenterPosition(), kuti.getOrientation(), Math.max(SimulParams.WORLD_WIDTH, SimulParams.WORLD_HEIGHT));
       
        
        Iterator it = points.iterator();
        while(it.hasNext()){
            Point2D p = (Point2D) it.next();
            lawnProfile.add(lawn[(int)(p.getY())][(int)(p.getX())]);
        }
        
    }
    
    
}
